package com.yuexin.project.account.controller;


import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yuexin.common.utils.poi.ExcelUtil;
import com.yuexin.common.utils.security.ShiroUtils;
import com.yuexin.framework.aspectj.lang.annotation.Log;
import com.yuexin.framework.aspectj.lang.enums.BusinessType;
import com.yuexin.framework.web.controller.BaseController;
import com.yuexin.framework.web.domain.AjaxResult;
import com.yuexin.framework.web.page.TableDataInfo;
import com.yuexin.project.account.domain.AccountList;
import com.yuexin.project.account.service.AccountListService;

/**
 * 厨房流水账 信息操作处理
 * 
 * @author yuexin
 * @date 2018-10-24
 */
@Controller
@RequestMapping("/account")
public class ListController extends BaseController
{
    private String prefix = "account/kitchenaccount";
	
	@Autowired
	private AccountListService listService;
	
	@RequiresPermissions("account:kitchenaccount:view")
	@GetMapping()
	public String list()
	{
	    return prefix + "/list";
	}
	
	/**
	 * 查询厨房流水账列表
	 */
	@RequiresPermissions("account:kitchenaccount:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(AccountList list)
	{
		System.out.println("查询");
		startPage();
		list.setCompanyId(ShiroUtils.getCompanyId());
        List<AccountList> accountlist = listService.selectListList(list);
		return getDataTable(accountlist);
	}
	
	/**
	 * 新增厨房流水账
	 */
	@GetMapping("/add")
	public String add()
	{
		System.out.println("新增");
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存厨房流水账
	 */
	@RequiresPermissions("account:kitchenaccount:add")
	@Log(title = "厨房流水账", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(AccountList list)
	{		
		list.setCompanyId(ShiroUtils.getCompanyId());
		list.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(listService.insertList(list));
	}

	/**
	 * 修改厨房流水账
	 */
	@GetMapping("/edit/{accountId}")
	public String edit(@PathVariable("accountId") Integer accountId, ModelMap mmap)
	{
		AccountList list = listService.selectListById(accountId);
		mmap.put("list", list);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存厨房流水账
	 */
	@RequiresPermissions("account:kitchenaccount:edit")
	@Log(title = "厨房流水账", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(AccountList list)
	{		
		list.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(listService.updateList(list));
	}
	
	/**
	 * 删除厨房流水账
	 */
	@RequiresPermissions("account:kitchenaccount:remove")
	@Log(title = "厨房流水账", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(listService.deleteListByIds(ids));
	}
	
	/**
	 * 导出 
	 */
	@Log(title = "列表", businessType = BusinessType.EXPORT)
    @RequiresPermissions("account:kitchenaccount:export")
    @PostMapping("/exportAccountlist")
    @ResponseBody
    public AjaxResult export(AccountList accountList)
    {
		System.out.println("导出");
		
        List<AccountList> list = listService.selectListList(accountList);
        ExcelUtil<AccountList> util = new ExcelUtil<AccountList>(AccountList.class);
        return util.exportExcel(list, "accountList");
    }
	
}
